<!doctype html>
<html class="theme-next use-motion theme-next-mist">
<head>
  

<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






  <link rel="stylesheet" type="text/css" href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5"/>




<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.4.5.1"/>


    <meta name="description" content="Valo's Blog" />



  <meta name="keywords" content="CoreAnimation,Objective-C," />





  <link rel="shorticon icon" type="image/x-icon" href="/favicon.ico?v=0.4.5.1" />


<meta name="description" content="最近在使用FMDB处理SQL文件时,内存消耗过大,以至于在iPhone4s(iOS7.1)上APP直接闪退.具体原因是因为处理SQL文件是一开始用的NSArray.总共十万条左右的数据,结果内存消耗超过1G…..改用NSInputStream逐行处理后, 内存消耗降至247M左右, 处理完成后将FMDB queue置为nil,内存消耗降至150M左右 ,恢复一个正常值.
1 逐行处理大文件的方法如">
<meta property="og:type" content="article">
<meta property="og:title" content="使用NSInputStream逐行处理大文件">
<meta property="og:url" content="http://yoursite.com/2015/08/17/使用NSInputStream逐行处理大文件/index.html">
<meta property="og:site_name" content="Valo's Blog">
<meta property="og:description" content="最近在使用FMDB处理SQL文件时,内存消耗过大,以至于在iPhone4s(iOS7.1)上APP直接闪退.具体原因是因为处理SQL文件是一开始用的NSArray.总共十万条左右的数据,结果内存消耗超过1G…..改用NSInputStream逐行处理后, 内存消耗降至247M左右, 处理完成后将FMDB queue置为nil,内存消耗降至150M左右 ,恢复一个正常值.
1 逐行处理大文件的方法如">
<meta property="og:updated_time" content="2015-08-18T02:44:19.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用NSInputStream逐行处理大文件">
<meta name="twitter:description" content="最近在使用FMDB处理SQL文件时,内存消耗过大,以至于在iPhone4s(iOS7.1)上APP直接闪退.具体原因是因为处理SQL文件是一开始用的NSArray.总共十万条左右的数据,结果内存消耗超过1G…..改用NSInputStream逐行处理后, 内存消耗降至247M左右, 处理完成后将FMDB queue置为nil,内存消耗降至150M左右 ,恢复一个正常值.
1 逐行处理大文件的方法如">


<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post'
  };
</script>

  <title> 使用NSInputStream逐行处理大文件 | Valo's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  

  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?52202e65c10bcc306b0e612bc89ff8d3";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <div class="container one-column page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><h1 class="site-meta">
  <span class="logo-line-before"><i></i></span>
  <a href="/" class="brand" rel="start">
      <span class="logo">
        <i class="icon-next-logo"></i>
      </span>
      <span class="site-title">Valo's Blog</span>
  </a>
  <span class="logo-line-after"><i></i></span>
</h1>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu ">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon icon-next-home"></i> <br />
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            <i class="menu-item-icon icon-next-categories"></i> <br />
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            <i class="menu-item-icon icon-next-about"></i> <br />
            关于
          </a>
        </li>
      

      
      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content"> 

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">

      
      
        <h1 class="post-title" itemprop="name headline">
          
          
            
              使用NSInputStream逐行处理大文件
            
          
        </h1>
      

      <div class="post-meta">
        <span class="post-time">
          发表于
          <time itemprop="dateCreated" datetime="2015-08-17T22:36:06+08:00" content="2015-08-17">
            2015-08-17
          </time>
        </span>

        
          <span class="post-category" >
            &nbsp; | &nbsp; 分类于
            
              <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                <a href="/categories/旧博客/" itemprop="url" rel="index">
                  <span itemprop="name">旧博客</span>
                </a>
              </span>

              
              

            
          </span>
        

        
          
            <span class="post-comments-count">
              &nbsp; | &nbsp;
              <a href="/2015/08/17/使用NSInputStream逐行处理大文件/#comments" itemprop="discussionUrl">
                <span class="post-comments-count ds-thread-count" data-thread-key="2015/08/17/使用NSInputStream逐行处理大文件/" itemprop="commentsCount"></span>
              </a>
            </span>
          
        
      </div>
    </header>

    <div class="post-body">

      
      

      
        <span itemprop="articleBody"><p>最近在使用FMDB处理SQL文件时,内存消耗过大,以至于在iPhone4s(iOS7.1)上APP直接闪退.<br>具体原因是因为处理SQL文件是一开始用的NSArray.总共十万条左右的数据,结果内存消耗超过1G…..<br>改用NSInputStream逐行处理后, 内存消耗降至247M左右, 处理完成后将FMDB queue置为nil,内存消耗降至150M左右 ,恢复一个正常值.</p>
<p>1 逐行处理大文件的方法如下:</p>
<pre><code><span class="comment">/**
 *  逐行处理大文件
 *
 *  @param filePath        本地文件路径
 *  @param delimiterString 分隔字符串
 *  @param process         处理每一行数据的block
 *  @param completion      处理完成之后的block
 */</span>
+ (<span class="keyword">void</span>)enumerateLinesOfFile:(<span class="built_in">NSString</span> *)filePath
               withDelimiter:(<span class="built_in">NSString</span> *)delimiterString
                     process:(<span class="keyword">void</span> (^)(<span class="built_in">NSInteger</span>, <span class="built_in">NSString</span> *))process
                  completion:(<span class="keyword">void</span> (^)(<span class="built_in">NSInteger</span>))completion{
    <span class="built_in">NSUInteger</span> lineNumber       = <span class="number">0</span>;
    <span class="built_in">NSMutableData</span> *dataChunk    = <span class="literal">nil</span>;
    <span class="built_in">NSData</span> *delimiter           = [delimiterString dataUsingEncoding:GB2312_ENCODING];
    <span class="built_in">NSInputStream</span> *inputStream  = [[<span class="built_in">NSInputStream</span> alloc] initWithFileAtPath:filePath];
    [inputStream open];

    <span class="keyword">while</span> (<span class="literal">YES</span>){
        <span class="built_in">NSMutableData</span> *buffer = [[<span class="built_in">NSMutableData</span> alloc] initWithLength:<span class="number">4</span> * <span class="number">1024</span>];
        <span class="built_in">NSInteger</span> length     = [inputStream read:[buffer mutableBytes] maxLength:[buffer length]];
        <span class="keyword">if</span> (length &lt;= <span class="number">0</span>) {
            <span class="keyword">break</span>;
        }
        <span class="keyword">if</span> (dataChunk) {
            [dataChunk appendData:buffer];
        }
        <span class="keyword">else</span>{
            dataChunk = [buffer mutableCopy];
        }
        <span class="keyword">if</span> (dataChunk<span class="variable">.length</span> &gt; <span class="number">0</span>) {
            <span class="comment">// 数据的当前位置</span>
            <span class="built_in">NSUInteger</span> location = <span class="number">0</span>;
            <span class="keyword">while</span> (<span class="literal">YES</span>) {
                <span class="comment">// 使用分隔符分隔一行</span>
                <span class="built_in">NSRange</span> rangeOfDelimiter = [dataChunk rangeOfData:delimiter
                                                          options:<span class="number">0</span>
                                                            range:<span class="built_in">NSMakeRange</span>(location, dataChunk<span class="variable">.length</span> - location)];
                <span class="keyword">if</span> (rangeOfDelimiter<span class="variable">.length</span> == <span class="number">0</span>) {
                    <span class="keyword">break</span>;
                }
                <span class="built_in">NSRange</span> rangeOfNewLine = <span class="built_in">NSMakeRange</span>(location, rangeOfDelimiter<span class="variable">.location</span> - location + delimiter<span class="variable">.length</span>);
                <span class="comment">//取得数据</span>
                <span class="built_in">NSData</span> *everyComponent = [dataChunk subdataWithRange:rangeOfNewLine];
                <span class="built_in">NSString</span> *component = [[<span class="built_in">NSString</span> alloc] initWithData:everyComponent encoding:GB2312_ENCODING];
                <span class="comment">// 处理数据</span>
                <span class="keyword">if</span> (component) {
                    lineNumber ++;
                    process(lineNumber, component);
                }
                <span class="comment">// 标记当前位置</span>
                location = <span class="built_in">NSMaxRange</span>(rangeOfNewLine);
            }
            <span class="keyword">if</span> (location &lt; dataChunk<span class="variable">.length</span>) {
                <span class="built_in">NSData</span> *reminder = [dataChunk subdataWithRange:<span class="built_in">NSMakeRange</span>(location, dataChunk<span class="variable">.length</span> - location)];
                dataChunk = [reminder mutableCopy];
            }
        }
    }
    <span class="keyword">if</span> (dataChunk<span class="variable">.length</span> &gt; <span class="number">0</span>) {
        <span class="built_in">NSString</span> *component = [[<span class="built_in">NSString</span> alloc] initWithData:dataChunk encoding:GB2312_ENCODING];
        <span class="keyword">if</span> (component) {
            lineNumber ++;
            process(lineNumber, component);
        }
    }
    [inputStream close];
    <span class="keyword">if</span> (completion) {
        completion(lineNumber);
    }
}
</code></pre><p>2 FMDB queue处理数据的语句</p>
<pre><code><span class="comment">//对数据库进行操作</span>
[self.writeQueue <span class="string">inTransaction:</span>^(FMDatabase *db, BOOL *rollback) {
    <span class="keyword">for</span> (NSString *tbl <span class="keyword">in</span> argsArray) {
        NSString *dropTableSql = [NSString <span class="string">stringWithFormat:</span> @<span class="string">"DELETE FROM %@"</span>, tbl];
        [db <span class="string">executeUpdate:</span> dropTableSql];
    }
    <span class="comment">//  执行 SQL 语句</span>
    [XXFileReader <span class="string">enumerateLinesOfFile:</span>sqlFilePath <span class="string">withDelimiter:</span>@<span class="string">"\n"</span> <span class="string">process:</span>^(NSInteger lineNumber, NSString *line) {
        NSString *sqlLine = [line <span class="string">stringByReplacingOccurrencesOfString:</span>@<span class="string">";"</span> <span class="string">withString:</span>@<span class="string">""</span>];
        sqlLine = [sqlLine <span class="string">stringByReplacingOccurrencesOfString:</span>@<span class="string">"\r"</span> <span class="string">withString:</span>@<span class="string">""</span>];
        <span class="keyword">if</span> (!([sqlLine <span class="string">isEqualToString:</span>@<span class="string">""</span>] || [sqlLine <span class="string">isEqualToString:</span>@<span class="string">"\n"</span>])) {
            [db <span class="string">executeUpdate:</span>sqlLine];
        }
    } <span class="string">completion:</span>nil];
}];
<span class="comment">// 关闭数据库后设置为nil,以便释放内存</span>
[self.writeQueue close];
self.writeQueue = nil;
</code></pre></span>
      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/CoreAnimation-Objective-C/" rel="tag">#CoreAnimation,Objective-C</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/08/17/关于CoreAnimation的几个关键点/" rel="prev">关于CoreAnimation的几个关键点</a>
            
          </div>

          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/08/17/Hello-hexo/" rel="next">Hello,hexo</a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>

 </div>

        
            <!-- 多说热评文章-->
            <p>热评文章</p>
            <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>
        

        
          <div class="comments" id="comments">
            
              <div class="ds-thread" data-thread-key="2015/08/17/使用NSInputStream逐行处理大文件/"
                   data-title="使用NSInputStream逐行处理大文件" data-url="http://yoursite.com/2015/08/17/使用NSInputStream逐行处理大文件/">
              </div>
            
          </div>
        
      </div>

      
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" src="http://himg.bdimg.com/sys/portrait/item/bbf1706f7a693131398c00" alt="Valo" itemprop="image"/>
          <p class="site-author-name" itemprop="name">Valo</p>
        </div>
        <p class="site-description motion-element" itemprop="description">Valo's Blog</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/">
              <span class="site-state-item-count">3</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            <a href="/categories">
              <span class="site-state-item-count">2</span>
              <span class="site-state-item-name">分类</span>
              </a>
          </div>

          <div class="site-state-item site-state-tags">
            
              <span class="site-state-item-count">2</span>
              <span class="site-state-item-name">标签</span>
              
          </div>

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/pozi119" target="_blank">GitHub</a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="http://creativecommons.org/licenses/zero/4.0" class="cc-opacity" target="_blank">
              <img src="/images/cc-zero.svg" alt="Creative Commons" />
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator"></div>
          <div class="post-toc">
            
            
              <p class="post-toc-empty">此文章未包含目录</p>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator"></div>
        </section>
      

    </div>
  </aside>


    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner"> <div class="copyright" >
  
  &copy; &nbsp; 
  <span itemprop="copyrightYear">2015</span>
  <span class="with-love">
    <i class="icon-next-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Valo</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


 </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  
  
    

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"pozi119"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>
    
     
  	<script src="/js/ua-parser.min.js"></script>
  	<script src="/js/hook-duoshuo.js"></script>
  

    
  
  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.1"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.1"></script>
  

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/js/motion_global.js?v=0.4.5.1" id="motion.global"></script>




  <script type="text/javascript" src="/js/nav-toggle.js?v=0.4.5.1"></script>
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  
<script type="text/javascript" src="/js/bootstrap.scrollspy.js?v=0.4.5.1" id="bootstrap.scrollspy.custom"></script>


<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 0.4 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    var $tocContent = $('.post-toc-content');
    if (isDesktop() && CONFIG.sidebar === 'post') {
      if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
        displaySidebar();
      }
    }
  });
</script>



  <script type="text/javascript">
    $(document).ready(function () {
      if (CONFIG.sidebar === 'always') {
        displaySidebar();
      }
      if (isMobile()) {
        FastClick.attach(document.body);
      }
    });
  </script>

  

  
  

  
  <script type="text/javascript" src="/js/lazyload.js"></script>
  <script type="text/javascript">
    $(function () {
      $("#posts").find('img').lazyload({
        placeholder: "/images/loading.gif",
        effect: "fadeIn"
      });
    });
  </script>
</body>
</html>
